package com.example.filetest;


/*
 * treeset练习
 * */

import com.example.domain.Student;

import java.util.Comparator;
import java.util.TreeSet;

public class Test01 {
    public static void main(String[] args) {

        Student zhangsan = new Student("zhangsan", 18);
        Student lishi = new Student("lishi", 19);
        Student dahuang = new Student("dahuang", 19);


        TreeSet<Student> students = new TreeSet<>(new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                int i = o1.getAge() - o2.getAge();
                i = i == 0 ? o1.getName().compareTo(o2.getName()) : i;
                return i;
            }
        });


        students.add(zhangsan);
        students.add(lishi);
        students.add(dahuang);


        System.out.println(students);

    }
}
